/**
 * 
 */
package org.ssh2Maven.action;

import org.ssh2Maven.model.systemModel.SystemUser;
import org.ssh2Maven.model.systemModelUtility.SystemEnums.Status;
import org.ssh2Maven.service.systemService.UserService;

import com.opensymphony.xwork2.ActionSupport;

/**
 * @author guangz
 * 
 */
public class UserManagerAction extends ActionSupport
{
	private static final long serialVersionUID = 1L;
	
	private UserService userService;

	private SystemUser user;
	private Boolean rememberMe;
	
	private String ajaxResult;

	public SystemUser getUser()
	{
		return user;
	}

	public void setUser(SystemUser user)
	{
		this.user = user;
	}

	public Boolean getRememberMe()
	{
		return rememberMe;
	}

	public void setRememberMe(Boolean rememberMe)
	{
		this.rememberMe = rememberMe;
	}

	public UserService getUserService()
	{
		return userService;
	}

	public void setUserService(UserService userService)
	{
		this.userService = userService;
	}

	public String ajaxCheckUserLogin()
	{
		if (user != null)
		{
			SystemUser loginUser = userService.checkUser(user.getLoginId(), user.getPassword());

			if (loginUser != null && !Status.DISABLED.equals(loginUser.getUserStatus()))
			{
				ajaxResult = "{\"loginStatus\":\"success\",\"msg\":\"\"}";
			}
			else
			{
				ajaxResult = "{\"loginStatus\":\"failure\",\"msg\":\"用户名或密码错误！\"}";
			}
		}

		return SUCCESS;
	}

	public String getAjaxResult()
	{
		return ajaxResult;
	}

	public void setAjaxResult(String ajaxResult)
	{
		this.ajaxResult = ajaxResult;
	}
}
